MySQL MIN() and MAX() Functions
The MIN
and MAX
functions are used to return the min and max value of the selected column.
Assume the following table to which we will use the min and max function in the query.
empno | name | age | role | location |
---|---|---|---|---|
001 | Andrew | 30 | Manager | India |
002 | Beslin | 28 | Business Analyst | India |
003 | Joanna | 23 | Senior Developer | USA |
004 | Rayan | 26 | Technical Lead | Canada |
MIN() function
The MIN
function is used to return the minimum value in the specified column.
Syntax for MIN() function
SELECT MIN(column_name)
FROM table_name
WHERE condition;
Example
select min(age) as Junior
from employee;
Output
Junior |
---|
23 |
MAX() function
The MAX
function is used to return the maximum value in the specified column.
Syntax for MIN() function
SELECT MAX(column_name)
FROM table_name
WHERE condition;
Example
select max(age) as Senior
from employee;
Output
Senior |
---|
30 |